import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:my_frist_flutter_app/cookbook/persistence/reading_writing_files.dart';
import 'dart:io';

main() {
  setUpAll(() async {
    // Create a temporary directory to work with
    final directory = await Directory.systemTemp.createTemp();

    // Mock out the MethodChannel for the path_provider plugin
    const MethodChannel('plugins.flutter.io/path_provider')
        .setMockMethodCallHandler((MethodCall methodCall) async {
      // If you're getting the apps documents directory, return the path to the
      // temp directory on the test environment instead.
      if (methodCall.method == 'getApplicationDocumentsDirectory') {
        return directory.path;
      }
      return null;
    });
  });

  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    // Build our app and trigger a frame.
    await tester.pumpWidget(FileDemo());

    // Verify that our counter starts at 0.
    expect(find.text('Button tapped times.'), findsOneWidget);
    expect(find.text('Button tapped time.'), findsNothing);

    // Tap the '+' icon and trigger a frame.
    final button = find.byTooltip('Increment');
    final icon = find.byIcon(Icons.add);
    await tester.tap(icon);
    // await tester.tap(find.byIcon(Icons.add));
    await tester.pump();

    // Verify that our counter has incremented.
    expect(find.text('Button tapped time.'), findsNothing);
    expect(find.text('Button tapped times.'), findsOneWidget);
  });
}
